Skip to content

Fix negative streak handling in getFreebuffStreakGlmWeeklyUnits - #1233

Open
pavankumar-vh wants to merge 1 commit into
CodebuffAI:mainfrom
pavankumar-vh:fix/streak-glm-negative-validation
Open

Fix negative streak handling in getFreebuffStreakGlmWeeklyUnits#1233
pavankumar-vh wants to merge 1 commit into
CodebuffAI:mainfrom
pavankumar-vh:fix/streak-glm-negative-validation

Conversation

@pavankumar-vh

Copy link
Copy Markdown

Overview

Fix negative streak handling in the getFreebuffStreakGlmWeeklyUnits function in common/src/util/freebuff-streak.ts.

Bug Description

The function didn't validate that streak is non-negative. If streak was negative, Math.floor(streak / INTERVAL) would be negative, and Math.min with the positive max would return the negative value, resulting in a negative GLM bonus.

Fix

Added Math.max(0, streak) to ensure streak is non-negative before processing.

Testing

All existing tests pass (14/14).

Files Changed

  • common/src/util/freebuff-streak.ts - Added negative streak validation

Scope

This change only touches common/ which is an approved contribution area per the Contributing Guide.

The function didn't validate that streak is non-negative. If streak was negative,
Math.floor(streak / INTERVAL) would be negative, and Math.min with the positive
max would return the negative value, resulting in a negative GLM bonus.

Added Math.max(0, streak) to ensure streak is non-negative before processing.
@codebuff-team

Copy link
Copy Markdown
Contributor

Thanks for the contribution - the fix itself is small, correct, and in-scope (common/).

The logic checks out: Math.floor(negative / INTERVAL) would indeed yield a negative tier count, and clamping with Math.max(0, streak) prevents that. No objection to the change itself.

A few things that would make this more mergeable:

  1. No test added. You mention "14/14 tests pass" but that's just confirming you didn't break anything, not that you covered the new behavior. A one-line test case like expect(getFreebuffStreakGlmWeeklyUnits(-5)).toBe(0) would make this a slam dunk.
  2. Is negative streak actually reachable? If streak is always derived from a day-count or array length upstream, this may be defensive code guarding against a case that can't occur, which is fine but worth noting in the PR body - callers of this function want to know whether it's a real observed bug or preventative hardening.

As-is, it's not wrong, just under-verified for a numeric edge case fix. Add the test and clarify whether this was found via a real negative streak value in production, and it should be an easy 3-line port.

@codebuff-team codebuff-team added bot:triaged Classified by the community triage bot pr:needs-work Right idea, not mergeable as written labels Sep 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:triaged Classified by the community triage bot pr:needs-work Right idea, not mergeable as written

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants